
import '//compiler' Token CompileContext Parser rootContext;


var WORD_SIZE 4;

Token.svar a;
Token.svar b;

# XXX these don't work any more because variable allocations no longer happen
# at the point of initialization.  We need a way to get the address of a
# particular stack var as a word so we can do mathematical comparisons on it.
#if ((a - b) != WORD_SIZE * 5) puts 'FAILED token allocation'
#if (after != (a - WORD_SIZE)) puts 'FAILED svar referencing'
if (a.type != 0) puts 'FAILED initializing type'

module 'compiler.test' {
    import '//compiler' Token CompileContext Parser rootContext;

    #ASTNode TestAST {
    #    defun init(self) {}
    #    defun del(self) {}
    #    defun emit(cg) {}
    #}

    Parser TestParser {
        defun init(self) {
          puts 'allocating a TestParser!'
        }
        defun del(self) {}
        defun parse(self context) {
            Token.svar tok;
            CompileContext.promote context;
            context.getToken tok;
    #        TestAST.new
        }
    }

    # this seems to be seg-faulting because the root context is zero
    CompileContext.svar context rootContext;

    # adding these to the current context doesn't really make very much sense, but
    # it does let us import it.
    #context.add 'foo' TestParser.new

#    defcommand foo TestParser.new
    # just checking to see if we can allocate one of these
    var v TestParser.new
}

#import 'compiler.test' foo;

# things we could reasonably do with this:
# 1) add it to the root context symtab, making it part of the language
# 2) create a new CompileContext symtab, add it to the new context and use it to
#    compile some nested module.
# 3) add it to the module's own symbol table during execution, making it
#    available to all importing modules.
# None of these things will affect the compile of the current module.

# this is dying because we're registering the UserParser that wraps TestParser
# as "TestParser".  "TestParser" needs to be bound to something like a class
# variable which is an instance of a type with at least a "new" function in
# the symbol table.  The "new" function should allocate an instance of
# TestParser and call the TestParser.init vtable method on it.
#context.exec {
#    foo some-token
#    puts 'did execed context'
#}

#foo some-token

puts 'ok'


